package com.chem.lems.repository;

import com.chem.lems.entity.Menus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface MenusRepository extends JpaRepository<Menus, Integer> {

    @Query(value = "SELECT * FROM elms_menu t WHERE t.menu_level=?1",nativeQuery = true)
    List<Menus> findAllByLevel(int level);

    @Query(value = "SELECT * FROM elms_menu t WHERE t.menu_pid=?1",nativeQuery = true)
    List<Menus> findAllByMenuPid(int pid);

    @Query(value = "SELECT menu_id FROM elms_role_menu t WHERE  t.role_id =?1",nativeQuery = true)
    List<Integer> findMenusByRole(String roleId);

    @Query(value = "SELECT * FROM elms_role_menu WHERE role_id=?1 AND menu_id=?2",nativeQuery = true)
    Map findRoleMenus(String roleId,int menuId);
}

